#include "Teacher.h"
#include <stdio.h>
#include <string.h>

void InitTeacher(Teach *t, const char *name, int age)
{
    t->age = age;
    t->size = 0;
    strcpy(t->Name, name);
}

void InsertStu(Teach *t, int id, const char *StuName)
{
    if (t->size == StuSize)
    {
        printf("数组已满，不允许再插入学生数据\n");
        return;
    }
    InitStu(&t->s[t->size++], id, StuName);
}

void RemoveByIndex(Teach *t, int index)
{
    for (int i = index; i < t->size - 1; i++)
    {
        t->s[i] = t->s[i + 1];
    }
    t->size--;
}

void RmStuByID(Teach *t, int ID)
{
    for (int i = 0; i < t->size; i++)
    {
        if (t->s[i].id == ID)
        {
            RemoveByIndex(t, i);
            i--;
        }
    }
}

void RmStuByName(Teach *t, const char *name)
{
    for (int i = 0; i < t->size; i++)
    {
        if (strcmp(t->s[i].Name, name) == 0)
        {
            RemoveByIndex(t, i);
            i--;
        }
    }
}

Stu *FindStuByName(Teach *t, const char *name)
{
    for (int i = 0; i < t->size; i++)
    {
        if (strcmp(t->s[i].Name, name) == 0)
        {
            return &t->s[i];
        }
    }
    return NULL;
}

void PrintTeacher(Teach *t)
{
    printf("老师姓名：%s 年龄：%d\n", t->Name, t->age);
    printf("学生信息：\n");
    for (int i = 0; i < t->size; i++)
    {
        PrintStu(&t->s[i]);//上面形参是指针，下面肯定要传地址
    }
}

